<!--
+----------------------------------------------------------------------
| 友得云客  - 开启房产营销新纪元
+----------------------------------------------------------------------
| Copyright (c) 2019~2023 优得（西安）信息科技有限公司版权所有
+----------------------------------------------------------------------
| Licensed 友得云客不是自由软件 未经允许不可移除相关版权
+----------------------------------------------------------------------
| Author: www.youdeyunke.com
+----------------------------------------------------------------------
-->
<template>
  <div class="app-container">
    <el-card>
      <div slot="title" class="form-title-slot">
        <div class="title-name">
          <b>厂房信息管理维护</b>
        </div>
      </div>
      <div class="form-tabs">
        <el-tabs tab-position="left" v-model="activeName">
          <el-tab-pane name="baseinfoSet" label="基本信息" v-if="btns.update_post_baseinfo">
            <div v-if="activeName == 'baseinfoSet'">
              <baseinfo-manager :post-id="pid"></baseinfo-manager>
            </div>
          </el-tab-pane>

          <el-tab-pane name="bannerSet" label="轮播头图" v-if="btns.update_post_banner">
            <div v-if="activeName == 'bannerSet'">
              <banner-manager :post-id="pid"></banner-manager>
            </div>
          </el-tab-pane>

          <el-tab-pane name="detailSet" label="详细介绍" v-if="btns.update_post_detailcontent">
            <div v-if="activeName == 'detailSet'">
              <detail-content-manager
                :detail-content-id="post.detail_content_id"></detail-content-manager>
            </div>
          </el-tab-pane>
          <el-tab-pane name="xiangceSet" label="厂房相册" v-if="btns.update_post_xiangce">
                        <span v-if="post.spider_id" slot="label" style="display: flex;align-items: center;">
                            <el-tooltip effect="dark" content="可AI抓取" placement="top">
                                <i class="icon-ai"></i> </el-tooltip>厂房相册</span>
            <div v-if="activeName == 'xiangceSet'">
              <xiangce-manager target-type="post" :target-id="pid"
                               :show-ai-spider="post.spider_id ? true : false"></xiangce-manager>
            </div>
          </el-tab-pane>
          <el-tab-pane name="metaSet" label="厂房参数" v-if="btns.update_post_metacontent">
                        <span v-if="post.spider_id" slot="label" style="display: flex;align-items: center;">
                            <el-tooltip effect="dark" content="可AI抓取" placement="top">
                                <i class="icon-ai"></i> </el-tooltip>厂房参数</span>
            <div v-if="activeName == 'metaSet'">
              <meta-content-manager :meta-content-id="post.meta_content_id" :post-id="post.id"
                                    :show-ai-spider="post.spider_id ? true : false"></meta-content-manager>
            </div>
          </el-tab-pane>
          <el-tab-pane name="videoSet" label="厂房视频" v-if="btns.update_post_video">
            <div v-if="activeName == 'videoSet'">
              <videos-manager :post-id="pid"></videos-manager>
            </div>
          </el-tab-pane>

<!--          <el-tab-pane name="qaSet" label="厂房问答" v-if="btns.update_post_qa">-->
<!--            <div v-if="activeName == 'qaSet'">-->
<!--              <qa-manager :post-id="pid"></qa-manager>-->
<!--            </div>-->
<!--          </el-tab-pane>-->


<!--          <el-tab-pane name="pointSet" label="厂房亮点" v-if="btns.update_post_point">-->
<!--            <div v-if="activeName == 'pointSet'">-->
<!--              <point-manager :post-id="pid"></point-manager>-->
<!--            </div>-->
<!--          </el-tab-pane>-->

<!--          <el-tab-pane name="reviewSet" label="厂房评测" v-if="btns.update_post_review">-->
<!--            <div v-if="activeName == 'reviewSet'">-->
<!--              <PostReviewManager :post-id="pid" :reviewEnable="post.review_enable"></PostReviewManager>-->
<!--            </div>-->
<!--          </el-tab-pane>-->


<!--          <el-tab-pane name="typeSet" label="户型设置" v-if="btns.update_post_type">-->
<!--                        <span v-if="post.spider_id" slot="label" style="display: flex;align-items: center;">-->
<!--                            <el-tooltip effect="dark" content="可AI抓取" placement="top">-->
<!--                                <i class="icon-ai"></i> </el-tooltip>户型设置</span>-->
<!--            <div v-if="activeName == 'typeSet'">-->
<!--              <types-manager :post-id="pid"-->
<!--                             :show-ai-spider="post.spider_id ? true : false"></types-manager>-->
<!--            </div>-->
<!--          </el-tab-pane>-->

<!--          <el-tab-pane name="saleSet" label="销控管理" v-if="btns.update_post_salecontrol">-->
<!--                        <span v-if="post.spider_id" slot="label" style="display: flex;align-items: center;">-->
<!--                            <el-tooltip effect="dark" content="可AI抓取" placement="top">-->
<!--                                <i class="icon-ai"></i> </el-tooltip>销控管理</span>-->
<!--            <div v-if="activeName == 'saleSet'">-->
<!--              <sale-control-manager @setZptHandle="setZpt" :post-id="pid"-->
<!--                                    :show-ai-spider="post.spider_id ? true : false"></sale-control-manager>-->
<!--            </div>-->
<!--          </el-tab-pane>-->

<!--          <el-tab-pane name="zptSet" label="总平图" v-if="btns.update_post_zpt">-->
<!--            <div v-if="activeName == 'zptSet'">-->
<!--              <dynamic-total-img-manager :post-id="pid"></dynamic-total-img-manager>-->
<!--            </div>-->
<!--          </el-tab-pane>-->


<!--          <el-tab-pane name="eventSet" label="厂房动态" v-if="btns.update_post_event">-->
<!--                        <span v-if="post.spider_id" slot="label" style="display: flex;align-items: center;">-->
<!--                            <el-tooltip effect="dark" content="可AI抓取" placement="top">-->
<!--                                <i class="icon-ai"></i> </el-tooltip>厂房动态</span>-->
<!--            <div v-if="activeName == 'eventSet'">-->
<!--              <event-manager :post-id="pid"-->
<!--                             :show-ai-spider="post.spider_id ? true : false"></event-manager>-->
<!--            </div>-->
<!--          </el-tab-pane>-->

<!--          <el-tab-pane name="brokerSet" label="置业顾问" v-if="btns.update_post_broker">-->
<!--            <div v-if="activeName == 'brokerSet'">-->
<!--              <PostBrokerManager :post-id="pid"></PostBrokerManager>-->
<!--            </div>-->
<!--          </el-tab-pane>-->

<!--          <el-tab-pane name="newsSet" label="相关资讯" v-if="btns.update_post_news">-->
<!--            <div v-if="activeName == 'newsSet'">-->
<!--              <news-manager :post-id="pid"></news-manager>-->
<!--            </div>-->
<!--          </el-tab-pane>-->


<!--          <el-tab-pane name="surroundSet" label="周边配套" v-if="btns.update_post_surround">-->
<!--            <div v-if="activeName == 'surroundSet'">-->
<!--              <surround-manager :post-id="pid"></surround-manager>-->
<!--            </div>-->
<!--          </el-tab-pane>-->

<!--          <el-tab-pane name="themeSet" label="风格设置" v-if="btns.update_post_theme">-->
<!--            <div v-if="activeName == 'themeSet'">-->
<!--              <theme-manager :post-id="pid"></theme-manager>-->
<!--            </div>-->
<!--          </el-tab-pane>-->

        </el-tabs>
      </div>
    </el-card>
  </div>
</template>

<style lang="scss" scope>
.form-tabs {
  user-select: none;
}

</style>

<script>
import DetailContentManager from "@/components/DetailContentManager/Index";
import MetaContentManager from "@/components/MetaContentManager/Index";
import XiangceManager from "@/components/XiangceManager/Index";
import {mapGetters} from "vuex";
import BannerManager from "./BannerManager/Index";
import BaseinfoManager from "@/components/PostBaseinfoManager/index";
import DynamicTotalImgManager from "./DynamicTotalImgManager/index.vue";
import EventManager from "./EventManager/index.vue";
import MapManager from "./MapManager/Index";
import NewsManager from "./NewsManager/Index";
import PointManager from "./PointsManager/Index.vue";
import PostBrokerManager from "./PostBrokerManager/Index.vue";
import PostReviewManager from "./PostReviewManager/Index.vue";
import QaManager from "./QaManager/Index.vue";
import SaleControlManager from "./SaleControlManager/index.vue";
import SurroundManager from "./SurroundManager/Index.vue";
import ThemeManager from "./ThemeManager/index.vue";
import TypesManager from "./TypesManager/Index";
import VideosManager from "./VideosManager/Index";

import {getPostDetail} from "@/api/post";

export default {
  components: {
    MapManager,
    BaseinfoManager,
    XiangceManager,
    TypesManager,
    DetailContentManager,
    MetaContentManager,
    NewsManager,
    VideosManager,
    BannerManager,
    PointManager,
    PostReviewManager,
    ThemeManager,
    QaManager,
    EventManager,
    SurroundManager,
    PostBrokerManager,
    SaleControlManager,
    DynamicTotalImgManager,
  },
  props: {
    // pid: { type: Number, default: null },
    btns: {type: Object, default: {}},
  },
  created() {
    var id = this.$route.params.id;
    this.pid = parseInt(id);
  },

  computed: {
    ...mapGetters(["user"]),

    addressTitles: function () {
      return ["所在区域", "项目名称", "项目地址"];
    },

    brokers_label: function () {
      return "置业顾问";
    },

    pageTitle: function () {
      var t = "厂房信息管理 ";
      return t;
    },

    groupName: function () {
      return "新房";
    },

    create_or_update_at_pretty: function () {
      var t = this.post.create_or_update_at;
      if (!t) {
        return "";
      }
      var ts = t.split("T");
      return ts[0] + " " + ts[1].split(".")[0];
    },
  },

  watch: {
    pid: {
      immediate: true,
      deep: true,
      handler(val) {
        // pass
        if (!val) {
          return;
        }
        this.loadData();
      },
    },
  },

  data() {
    return {
      loading: true,
      show: false,
      post: {},
      loading: false,
      pid: null,
      activeName: 'baseinfoSet',
    };
  },

  methods: {
    loadData: function () {
      this.loading = true;
      getPostDetail(this.pid).then((resp) => {
        this.loading = false;
        if (resp.status != 0) {
          return;
        }
        this.post = resp.data;
      });
    },
    publicHandle: function () {
      var _this = this;
      this.loading = true;
      var data = {is_public: this.post.public, id: this.post.id};
      updatePost(data).then((resp) => {
        _this.loading = false;
        if (resp.status == 0) {
          var msg = data.is_public ? "已上架" : "已下架";
          _this.$message.success(msg);
          _this.$emit("change", this.post);
        }
      });
    },

    setZpt() {
      this.activeName = 'zptSet';
    },

    openDialog: function () {
      this.show = true;
    },

    onClose: function () {
      this.show = false;
      console.log("on close click, emit start");
      this.$emit("close", null);
    },
  },
};
</script>
